#include <ctime>
#include <random>
#include <vector>
#include "binomial_heap.h"
#define BOOST_TEST_MAIN test
#include <boost/test/included/unit_test.hpp>

using namespace std;

#define Handle binomialHeap<int, int>::nodeHandle
BOOST_AUTO_TEST_CASE(Add_ExtractMin_Test)
{
    srand (time(NULL));
    std::vector<std::pair<int,int>> v;
    while (v.size() != 1000)
    {
        v.insert(v.begin(),std::pair<int,int>(abs(rand() % 10000),rand() % 1000));
    }

    int minPriority = 10001;
    int minData = 10001;
    int count = 0;
    while (count < 1000)
    {
        int priority = v[count].first;
        int value = v[count].second;
        if (priority < minPriority)
        {
            minPriority = priority;
            minData = value;
        }
        count++;
    }
    binomialHeap<int, int> heap(v);

    BOOST_CHECK_EQUAL(heap.minimum(), minData);
}
BOOST_AUTO_TEST_CASE(DecreaseValue_Test)
{
    std::vector<std::pair<int,int>> v;
    while (v.size() != 1000)
    {
        v.insert(v.begin(),std::pair<int,int>(abs(rand() % 10000),rand() % 1000));
    }

    int minPriority = 10001;
    int minData = 10001;
    int count = 0;
    while (count < 1000)
    {
        int priority = v[count].first;
        int value = v[count].second;
        if (priority < minPriority)
        {
            minPriority = priority;
            minData = value;
        }
        count++;
    }
    binomialHeap<int, int> heap(v);
    int priority =  abs(rand() % 10000);
    int value = rand() % 1000;

    BOOST_CHECK_EQUAL(heap.minimum(), minData);
    Handle h = heap.add(priority,value);
    heap.decreasePriority(h, -1);
    BOOST_CHECK_EQUAL(heap.minimum(), value);
    // наш хендл должен выжить
    heap.decreasePriority(h, -1000);
    BOOST_CHECK_EQUAL(heap.minimum(), value);
}

